home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / rspfdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-30  |  3.1 KB  |  132 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "netuser.h"
  5. #include "internet.h"
  6. #include "socket.h"
  7. #include "ip.h"
  8. #include "rspf.h"
  9.  
  10. #ifdef TNOS_68K
  11. #define fprintf traceprintf
  12. #endif
  13.  
  14. /* Dump an RSPF packet */
  15. void
  16. rspf_dump(fp,bpp,source,dest,check)
  17. FILE *fp;
  18. struct mbuf **bpp;
  19. int32 source,dest;
  20. int check;        /* If 0, bypass checksum verify */
  21. {
  22.     union rspf rspf;
  23.     struct pseudo_header ph;
  24.     int16 csum;
  25.     int sync;
  26.  
  27.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  28.         return;
  29.  
  30.     fprintf(fp,"RSPF: ");
  31.  
  32.     /* Compute checksum */
  33.     ph.source = source;
  34.     ph.dest = dest;
  35.     ph.protocol = RSPF_PTCL;
  36.     ph.length = len_p(*bpp);
  37.     if((csum = cksum(&ph,*bpp,ph.length)) == 0)
  38.         check = 0;    /* No checksum error */
  39.  
  40.     ntohrspf(&rspf,bpp);
  41.  
  42.     if(rspf.hdr.version != RSPF_VERSION)
  43.         fprintf(fp,"version %u ",rspf.hdr.version);
  44.     switch(rspf.hdr.type){
  45.     case RSPF_FULLPKT:
  46.         if(rspf.pkthdr.csum == 0)
  47.         check = 0;
  48.         fprintf(fp,"type ROUTING UPDATE ");
  49.         if(rspf.pkthdr.fragtot != 1)
  50.         fprintf(fp,"fragment %u frag total %u ",rspf.pkthdr.fragn,
  51.                rspf.pkthdr.fragtot);
  52.         if(rspf.pkthdr.sync != 4)
  53.         fprintf(fp,"sync %u ",rspf.pkthdr.sync);
  54.         fprintf(fp,"nodes %u id %u",rspf.pkthdr.nodes,rspf.pkthdr.envid);
  55.         if(check)
  56.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  57.         fprintf(fp,"\n");
  58.         if(rspf.pkthdr.sync != 0)
  59.         sync = rspf.pkthdr.sync - 4;
  60.         else
  61.         sync = len_p(*bpp);
  62.         if(sync % 5 != 0){
  63.         fprintf(fp,"      %d bytes\n",sync);
  64.         pullup(bpp,NULLCHAR,sync);
  65.         sync = 0;
  66.         }
  67.         rspfnodedump(fp,bpp,sync / 5);
  68.         break;
  69.     case RSPF_RRH:
  70.         if(rspf.rrh.csum == 0)
  71.         check = 0;
  72.         fprintf(fp,"type RRH seq 0x%04x flags %d",rspf.rrh.seq,rspf.rrh.flags);
  73.         if(check)
  74.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  75. #ifdef TNOS_68K
  76.         fprintf (fp, "\n");
  77. #else
  78.         putc('\n',fp);
  79. #endif
  80.         break;
  81.     default:
  82.         fprintf(fp,"Unknown packet type\n");
  83.     }
  84. }
  85.  
  86. void
  87. rspfnodedump(fp,bpp,adjcnt)
  88. FILE *fp;        /* uses tputs() if NULLFILE */
  89. struct mbuf **bpp;    /* routing update without packet header */
  90. int adjcnt;        /* number of links before first node header */
  91. {
  92.      int c, links = 0;
  93.      char buf[128];
  94.      struct rspfnodeh nodeh;
  95.      struct rspflinkh linkh;
  96.      *buf = '\0';
  97.      for(;;) {
  98.       if(*buf != '\0') {
  99.            if(fp != NULLFILE)
  100.             fputs(buf,fp);
  101.            else
  102.             tputs(buf);
  103.            *buf = '\0';
  104.       }
  105.       if(len_p(*bpp) == 0)
  106.            break;
  107.       if(adjcnt){
  108.            if((c = PULLCHAR(bpp)) == -1)
  109.             break;
  110.            sprintf(buf,"            %s/%u\n",inet_ntoa(pull32(bpp)),c);
  111.            adjcnt--;
  112.            continue;
  113.       }
  114.       if(links){
  115.            if(ntohrspflink(&linkh,bpp) == -1)
  116.             break;
  117.            sprintf(buf,"      horizon %u ERP factor %u cost %u adjacencies %u\n",
  118.                linkh.horizon,linkh.erp,linkh.cost,linkh.adjn);
  119.            adjcnt = linkh.adjn;
  120.            links--;
  121.            continue;
  122.       }
  123.       if(ntohrspfnode(&nodeh,bpp) == -1)
  124.            break;
  125.       sprintf(buf,"      Reporting Router: %s Seq %u Subseq %u links %u\n",
  126.           inet_ntoa(nodeh.addr),(int16)nodeh.seq,nodeh.subseq,
  127.           nodeh.links);
  128.       links = nodeh.links;
  129.      }
  130. }
  131.  
  132.